<template>
	<view class="pages exam">
		<my-header bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">练题列表</block>
		</my-header>
        <view class="num" @click="go()">当前练题总数{{examCur}}</view>
        
        <view class="examList">
            <view class="examItem" v-for="(item,index) in examNum/100" :key="index">
                <view class="title row">
                    第{{index+1}}组练习 {{index*100+1}}~{{index*100+100>examNum? examNum:index*100+100}}
                    <view class="begin row" :class="examCur/100>index||examCur==0&&index==0?'gree':'grey'"
                    @click="begin(examCur/100-1>index?2:examCur/100>index||examCur==0&&index==0?1:0,index)"
                    >
                        {{examCur/100-1>index||examCur==0?"开始复习":"开始练题"}}</view>
                </view>
                <view class="row">
                    当前进度：
                    <!-- {{examCur/100-1>index?100: examCur/100>index?examCur%100:0}} -->
                    <view class="progress-box">
                        <progress activeColor="#007aff" :percent="examCur/100-1>index?100: examCur/100>index?examCur%100:0" show-info  stroke-width="3" backgroundColor="#999"/>
                    </view>
                </view>
                
            </view>
        </view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
                examNum:0,
                examCur:0,
                path:""
			}
		}, 
		onLoad(opt){
            // practice 模拟考试
        },
        onShow(){
           this.initData();
        },
		methods: {
            go(){
                let page=uni.$pages.getKey
                console.log(page);
                uni.go(page)
            },
			async initData(){
               let driverInfo=uni.getStorageSync('driverInfo')
				const res=await uni.$request({
                    ...driverInfo,
                    is_exam:this.is_exam,
                    // cur:100
				},"api/driverExam/getExamNum")
                this.examNum=res.data.examNum
                this.examCur=res.data.examCur||0
            },
            begin(cur,index){
                let pages=index*1+1
                let examCur=cur==1&&this.examCur>1?this.examCur-index*100:1
                console.log(cur);
                if(cur==0){
                    uni.$err("请先完成前面的关卡")
                }else{
                    uni.navigateTo({
                         url: `./exam?pages=${pages}&examCur=${examCur}`
                    });
                }
            },
		}
	}
</script>

<style lang="scss">
    // @import "../main";
    $grey:$uni-text-color-grey;
    $gree:$uni-color-success;
    $gree:$col;
    .grey{
        background:$grey;
        color: $grey;
    }
    .gree{
        background:$gree;
        color: $gree;
    }
    .examList{
        .examItem{
            margin:20rpx 25rpx;
            padding: 20rpx;
            background: #fff;
            .title{
                height: 80rpx;
            
                .begin{
                    color: #fff;
                    width: 150rpx;
                    height: 50rpx;
                    border-radius: 5rpx;
                    justify-content: center;
                    margin-left: auto;
                }
            }
            .key{
                flex-shrink: 0;
            }
            .progress-box{
                flex-shrink: 0;
                width: 78%;
            }
        }
    }
</style>